package tech.aistar.day09;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * 本类用来演示: LinkedList
 *
 * @author: success
 * @date: 2022/7/28 9:12 上午
 */
public class LinkedListDemo {
    public static void main(String[] args) {
        LinkedList<String> linkedList = new LinkedList<>();

        linkedList.add("spring");
        linkedList.add("springboot");
        linkedList.add("springCloud");

        //根据下标查找
        //System.out.println(linkedList.get(1));

        //根据下标删除
        //System.out.println(linkedList.remove(1));//返回刚刚删除的元素

        //操作头和尾部
        linkedList.addFirst("mysql");
        //add和addLast

        //模拟栈的数据结构
        //压入栈顶
        linkedList.push("jdbc");
        //弹出栈顶 -> 删除
        System.out.println(linkedList.pop());

        linkedList.offerFirst("xxx");

        System.out.println(linkedList.getFirst());//获取头
        System.out.println(linkedList.getLast());//获取尾部

        System.out.println("=====");
        Iterator<String> iterator = linkedList.iterator();
        while(iterator.hasNext()){
            String e = iterator.next();
            System.out.println(e);
        }
    }
}
